<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>
<script>
    $(function () {
        $("#username").blur(function () {
            $.ajax({
                type: "POST",
                url: "/checkName",
                data: {"username": $("#username").val()},//document.getElementById("username").value
                success: function (result) {
                    // console.log("result---" + result);
                    if (result == "true") {
                        $("#msg").html("用户名已经存在").css("color", "red")
                        // document.getElementById("msg").innerHTML = "用户名已经存在"
                    } else {
                        $("#msg").html("可以登录").css("color", "green")
                        // document.getElementById("msg").innerHTML = "可以登录"
                    }
                },
            })
        });
    })
</script>
<body>
请输入注册账号：<input type="text" name="username" id="username">
<span id="msg"></span>

</body>
</html>